// 工单菜单的接口
import {
  request
} from '../request';
const UPLOAD_MOBILE_SIGN = 'MOBILE'; // 移动端上传附件标识，PC是DESKTOP

// 创建工单
export function serveCreateOrder(data, files) {
  let url = 'eis.simple?service=eamOrderService&method=createOrder';
  let fileStr = '';
  if (files?.length > 0) {
    files.forEach((item) => {
      if (item.source && item.source === 'MOBILE') {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=MOBILE`;
      } else {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=DESKTOP`;
      }
    });
    url += fileStr;
  }
  return request({
    url: url,
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 编辑草稿工单
export function serveEditWorkerOrder(data, files) {
  let url = 'eis.simple?service=eamOrderService&method=editWorkOrder';
  let fileStr = '';
  if (files?.length > 0) {
    files.forEach((item) => {
      if (item.source && item.source === 'MOBILE') {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=MOBILE`;
      } else {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=DESKTOP`;
      }
    });
    url += fileStr;
  }
  return request({
    url: url,
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 我创建的工单
// 所有工单(user:all)
export function fetchMyCreate(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryCreatedEamOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 我负责的工单
export function fetchMyRepair(data) {
  console.log('data', data);
  return request({
    url: 'eis.simple?service=eamOrderService&method=dutyUserQueryEamOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单详情
export function getWorkDetail(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=getMobileWorkOrderDetail',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单取消
// {orderSeq:'',textArea:''}
export function cancelWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=workOrderCancel',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单转办
// {orderSeq:'',changeUser:'',textArea:''}
export function transferWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=transferWorkOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单转办
export function changeDutyUser(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=changeDutyUser',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单保存
export function saveWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=saveWorkOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单完成
export function finishWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=finishWorkOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 历史工单
export function getWorkTrack(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryEamOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单反馈
export function feedbackWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=saveFeedback',
    method: 'post',
    isFormData: true,
    data: data
  });
}
// 查询工单反馈
export function getFeedbackWork(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryFeedback',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 新增工单任务
export function addWorkTask(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=createOrderTask',
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 删除工单任务
export function delWorkTask(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteOrderTask',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 编辑工单任务
export function editWorkTask(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=editWorkOrderTask',
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 查询工单任务
export function getWorkTask(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryOrderTask',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 查询备品备件
export function getSpares(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=querySpareParts',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 新增备品备件
export function addSpares(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=createSpareParts',
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 删除备品备件
export function delSpares(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteSpareParts',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 编辑备品备件
export function editSpares(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=editSpareParts',
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 工单新增员工
export function addWorkStaff(data) {
  console.log('api gongdanxinzneg');
  return request({
    url: 'eis.simple?service=eamOrderService&method=addOrderUser',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 查询工单员工
export function getWorkStaff(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryOrderUser',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单删除员工
export function delWorkStaff(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteOrderUser',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单编辑员工
export function editWorkStaff(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=editOrderUser',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单工作记录
export function getWorkRecord(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryOperateLog',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 工单详情--处理--工单保存
export function editWorkOrder(data, files) {
  let url = 'eis.simple?service=eamOrderService&method=editWorkOrder';
  let fileStr = '';
  if (files?.length > 0) {
    files.forEach((item) => {
      if (item.source && item.source === 'MOBILE') {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=MOBILE`;
      } else {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=DESKTOP`;
      }
    });
    url += fileStr;
  }

  return request({
    url: url,
    method: 'post',
    // isFormData: true,
    data: data
  });
}

// 工单详情--处理--工单完成
export function workOrderCompleteCheck(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=workOrderCompleteCheck',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 提交委外
export function editWorkOrderOutSource(data = {}) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=editWorkOrderOutSource',
    method: 'post',
    // isFormData: true,
    data: data
  });
}
